function updateMdlConfig(mdlName, varargin)
%updateMdlConfig upate model config to prj template
%   Update model configuration to that of the model template ensuring
%   project model consistency
%
%   updateMdlConfig(model name, config obj)
%   note - config obj is optional.  this is because we want to have the
%   option for this code to be ran with single model (interactive) or a loop where a
%   config obj already exist (import or batch use case)
%
%   

% the source of the model configuration will be in the model template
% directory
if isempty(varargin) % this is the single instance or interactive side of the code
    % check with user if they really wants to update config
    choice = questdlg('Do you want to update the model configuration?', ...
        'Confirm', 'Yes', 'No', 'Yes');
    if strcmp(choice, 'Yes')
        % set msg flag
        msgflg = true;
        % create a temp model to grab the configuration
        mdlTemplateDir = ProjectPathManager.getDirPath('prj config root');
        mdlTemplateName = fullfile(mdlTemplateDir, 'templates', 'model_templates', [ProjectNamingManager.getNameStr('model template') '.sltx']);
        % Create a new model.
        modelH = Simulink.createFromTemplate(mdlTemplateName);
        configObj = getActiveConfigSet(modelH);
        configObj.Name = ProjectNamingManager.getNameStr('model template');
    else
        return;
    end
else
    msgflg = false;
    configObj = varargin{1};
end
% attached the model template
load_system(mdlName);
% to prevent model config name issues, we must protect same names
% at the end, we should save the previous active config and have one from
% template
currentConfigObjSet = getConfigSets(mdlName);
currentActConfigObj = getActiveConfigSet(mdlName);
if numel(currentConfigObjSet) > 1
    currentConfigObjSet(strcmp(currentConfigObjSet, currentActConfigObj.Name)) = [];
    for i =  1:numel(currentConfigObjSet)
        detachConfigSet(mdlName, currentConfigObjSet{i});
    end
end
% rename the active set to - 'old_active_config'
currentActConfigObj.Name = 'old_active_config';
attachConfigSetCopy(mdlName, configObj);
setActiveConfigSet(mdlName, configObj.Name);

% if interactive case, then show a message
if msgflg
    % not saving the model after interactive
    bdclose(modelH);
    msgbox('Operation Completed','Success');
else
    % this is the automated loop
    save_system(mdlName);
    bdclose(mdlName);
end

end
















